<template>
	<div class="order-check">
		<el-breadcrumb class="bread-title" style="font-size:14px;">
			<el-breadcrumb-item>交易中心</el-breadcrumb-item>
			<el-breadcrumb-item>客户管理</el-breadcrumb-item>
			<el-breadcrumb-item>支付订单</el-breadcrumb-item>
		</el-breadcrumb>
		<el-form ref="form" :model="formData"  :inline="true">
			<el-form-item label="城市：">
				<el-select v-model="formData.cityId" size="small" style="width:150px;" @change="loadisOrdev" filterable>
					<el-option v-for="item in citys" :label="item.city" :value="item.cityId" :key="item.cityId"></el-option>
				</el-select>
			</el-form-item>
			<el-form-item label="客户：">
				<el-input size="small" v-model.trim="formData.customerName" placeholder="请输入客户姓名/手机号"></el-input>
			</el-form-item>
			<el-form-item label="订单号：">
				<el-input size="small" v-model.trim="formData.orderCode" placeholder="请输入订单号"></el-input>
			</el-form-item>
			<el-form-item label="订单交易状态：">
				<el-select v-model="formData.tradeStatus" style="width:150px;" size="small">
					<el-option v-for="item in tradeStatuss" :label="item.label" :value="item.value" :key="item.value"></el-option>
				</el-select>
			</el-form-item>
			<el-form-item label="楼盘名称：">
				<el-select v-model="formData.devId" size="small" filterable>
					<el-option v-for="(item,index) in devs" :label="item.devName" :value="item.devId" :key="index"></el-option>
				</el-select>
			</el-form-item>
			<el-form-item label="是否退款：">
				<el-select v-model="formData.refundFlag" style="width:80px;" size="small">
					<el-option v-for="item in refundFlags" :label="item.label" :value="item.value" :key="item.value"></el-option>
				</el-select>
			</el-form-item>
			<el-form-item label="提交H3状态：">
				<el-select v-model="formData.bpmSubmitStatus" style="width:150px;" size="small">
					<el-option v-for="item in bpmSubmitStatuss" :label="item.label" :value="item.value" :key="item.value"></el-option>
				</el-select>
			</el-form-item>
			<el-form-item label="H3审批状态：">
				<el-select v-model="formData.bpmAuditStatus" style="width:150px;" size="small">
					<el-option v-for="item in bpmAuditStatuss" :label="item.label" :value="item.value" :key="item.value"></el-option>
				</el-select>
			</el-form-item>
			<el-form-item label="运营审核人：">
				<el-input size="small" v-model.trim="formData.applyUserName" placeholder="请输入运营审核人"></el-input>
			</el-form-item>
			<el-form-item label="退款金额：">
				<el-input size="small" style="width:100px;" v-model.trim="formData.refundPaidBegin" placeholder="请输入"></el-input>-
				<el-input size="small" style="width:100px;" v-model.trim="formData.refundPaidEnd" placeholder="请输入"></el-input>
			</el-form-item>
			<el-form-item label="收款人：">
				<el-input size="small" v-model.trim="formData.recName" placeholder="请输入运营审核人"></el-input>
			</el-form-item>
			<el-form-item>
				<el-button type="primary" size="small" @click="query" id="monitorEnter">查询</el-button>
				<el-button type="primary" size="small" @click="resetForm">重置</el-button>
			</el-form-item>
		</el-form>
		<el-table :data="tableData" border stripe size="mini" @sort-change='tableSortChange'>
			<el-table-column type="index" label="序号" width="80" align="center"></el-table-column>
			<el-table-column width="100" label="城市" prop="cityName" :show-overflow-tooltip="true" align="center"></el-table-column>
			<el-table-column width="100" label="客户姓名" prop="customerName" :show-overflow-tooltip="true" align="center"></el-table-column>
			<el-table-column width="100" label="客户手机号" prop="customerPhone" :show-overflow-tooltip="true" align="center"></el-table-column>
			<el-table-column width="100" label="楼盘名称" prop="devName" :show-overflow-tooltip="true" align="center"></el-table-column>
			<el-table-column width="100" label="订单号" prop="orderCode" :show-overflow-tooltip="true" align="center"></el-table-column>
			<el-table-column width="100" label="订单交易状态" prop="tradeStatus" :show-overflow-tooltip="true" align="center" :formatter="initTradeStatus"></el-table-column>
			<el-table-column width="100" label="是否退款" prop="refundFlag" :show-overflow-tooltip="true" align="center" :formatter="initRefundFlag"></el-table-column>
			<el-table-column width="120" label="退款提交时间" prop="refundSubmitTime" :show-overflow-tooltip="true" align="center" sortable="custom" :sort-orders="['ascending', 'descending']"></el-table-column>
			<el-table-column width="100" label="退款" prop="isrefund" :show-overflow-tooltip="true" align="center">
				<template slot-scope="scope">
					<el-button type="text" disabled v-if="scope.row.bpmRejectStatus==6">审核</el-button>
					<el-button type="text" v-else-if="scope.row.refundStatus == 3 && scope.row.auditStatus != 6" @click="jumpDetail('check',scope.row.orderCode)">审核</el-button>
					<el-button type="text" v-else disabled >审核</el-button>
				</template>
			</el-table-column>
			<el-table-column width="100" label="退款金额" prop="refundPaid" :show-overflow-tooltip="true" align="center" :formatter="toFixedFn"></el-table-column>
			<el-table-column width="100" label="收款人" prop="recName" :show-overflow-tooltip="true" align="center"></el-table-column>
			<el-table-column width="100" label="退款审核状态" prop="auditStatus" :show-overflow-tooltip="true" align="center" :formatter="initAuditstatus"></el-table-column>
			<el-table-column width="100" label="运营审核人" prop="applyUserName" :show-overflow-tooltip="true" align="center"></el-table-column>
			<el-table-column width="100" label="提交H3状态" prop="bpmSubmitStatus" :show-overflow-tooltip="true" align="center" :formatter="initBpmsubStatus"></el-table-column>
			<el-table-column width="100" label="H3审批状态" prop="bpmAuditStatus" :show-overflow-tooltip="true" align="center" :formatter="initBpmsAudStatus"></el-table-column>
			<el-table-column label="操作" prop="operate" align="center" fixed="right" width="250">
				<template slot-scope="scope">
					<el-button type="text" size="small" :disabled="scope.row.merge==1" @click="hx(scope.row.orderCode)">核销</el-button>
					<el-button type="text" size="small" @click="jumpDetail('look',scope.row.orderCode)">查看详情</el-button>
					<el-button type="text" size="small" 
					:disabled="(roleType=='运营人员'||roleType=='系统管理员') && scope.row.bpmRejectStatus!=6" @click="jumpDetail('check',scope.row.orderCode)">重新提交</el-button>
					<el-button type="text" size="small" :disabled="scope.row.bpmSubmitStatus != 2 && scope.row.bpmSubmitStatus != 3" @click="lookProgress(scope.row.orderCode)">查看流程</el-button>
				</template>
			</el-table-column>
		</el-table>
		<el-pagination
			@size-change="handleSizeChange"
			@current-change="handleCurrentChange"
			:current-page="formData.pageNum"
			:page-sizes="[10, 20, 40, 50]"
			:page-size="formData.pageSize"
			layout="total, sizes, prev, pager, next, jumper"
			:total="total" style="margin-top:30px;">
		</el-pagination>
		<el-dialog title="核销" :visible.sync="FdialogVisible" width="30%">
			<el-form ref="form" :model="hxData" label-width="120px">
				<el-form-item label="跟进经纪人：">
					<span>{{hxData.brokerNames}}</span>
				</el-form-item>
				<el-form-item label="楼盘名称：">
					<span>{{hxData.devName}}</span>
				</el-form-item>
				<el-form-item label="房源：">
					<el-select v-model="hxData.house" size="small" @change="loadHouseName">
						<el-option v-for="(item,index) in hxhouse" :label="item.label" :value="item.value" :key="index"></el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="">
					<el-button type="primary" size="small" @click="confirmhx">核销</el-button>
				</el-form-item>
			</el-form>
		</el-dialog>
		<el-dialog title="核销" :visible.sync="SdialogVisible" width="30%">
			<el-form ref="form" :model="hxData" label-width="120px">
				<el-form-item label="客户：">
					<span>{{hxData.customerName}}</span>
				</el-form-item>
				<el-form-item label="跟进经纪人：">
					<span>{{hxData.brokerNames}}</span>
				</el-form-item>
				<el-form-item label="房源：">
					<span>{{hxData.houseName}}</span>
				</el-form-item>
				<el-form-item label="会员费：">
					<span>￥{{this.toFixedFn1(hxData.fee)}}</span>
				</el-form-item>
				<el-form-item label="操作：">
					<span>核销</span>
				</el-form-item>
				<el-form-item label="">
					<el-button type="primary" size="small" @click="hxconfirm">确定</el-button>
				</el-form-item>
			</el-form>
		</el-dialog>
	</div>
</template>

<script>
	export default {
		name:"payorderchecks",
		data(){
			return {
				roleType:JSON.parse(sessionStorage.getItem("cmsUser")).roleName,
				citys:[],
				tradeStatuss:[
					{value:"",label:"全部"},{value:"0",label:"认筹-已下单"},{value:"1",label:"认筹-待支付"},{value:"2",label:"认筹-已付款"},
					{value:"refunding",label:"认筹-退款中"},{value:"refund",label:"认筹-已退款"},{value:"refundFail",label:"认筹-退款拒绝"}
				],
				bpmSubmitStatuss:[
					{value:"",label:"全部"},{value:"1",label:"不可提交"},{value:"2",label:"提交成功"},{value:"3",label:"驳回待提交"},
				],
				bpmAuditStatuss:[
					{value:"",label:"全部"},{value:"1",label:"审核中"},{value:"2",label:"审核完成"},{value:"3",label:"审核失败"}
				],
				devs:[],
				refundFlags:[{value:"",label:"全部"},{value:"1",label:"是"},{value:"0",label:"否"}],
				formData:{
					cityId:"",
					customerNamePhone:"",
					orderCode:"",
					tradeStatus:"",
					tradeStatusAll:"",
					devId:"",
					bpmSubmitStatus:"",
					bpmAuditStatus:"",
					refundFlag:"",
					applyUserName:"",
					refundPaidBegin:"",
					refundPaidEnd:"",
					sortFlag:"desc",
					recName:"",
					pageNum:1,
					pageSize:10
				},
				tableData:[],
				total:0,
				hxhouse:[],
				FdialogVisible:false,
				SdialogVisible:false,
				hxData:{
					brokerNames:"",
					devName:"",
					house:"",
					brokerCustomerId:"",
					fee:"",
					customerName:"",
					orderCode:"",
					houseName:""
				}
			}
		},
		methods:{
			hxconfirm(){
				this.$axios.post(`/cms/posCmsOrder/merge/${this.hxData.orderCode}/${this.hxData.house}`).then((res) => {
	                this.$message({
						message:"操作成功",
						type: 'success',
						duration:1500,
						onClose:()=>{
							this.SdialogVisible=false;
							this.loadData();
						}
					});
	            });
			},
			loadHouseName(val){
				for(let i=0;i<this.hxhouse.length;i++){
					if(val==this.hxhouse[i].value){
						this.hxData.houseName=this.hxhouse[i].label;
					}
				}
			},
			confirmhx(){
				if(this.hxData.house==""){
					this.$message({
						message:"请选择房源，如果房源数据为空，请检查该订单是否有认购或签约记录",
						type: 'warning',
						duration:1500
					});
					return;
				}
				this.FdialogVisible=false;
				this.SdialogVisible=true
			},
			hx(orderCode){
				this.$axios.post(`/cms/posCmsOrder/mergeInfo/${orderCode}`).then((res) => {
	                console.log(res);
	                this.FdialogVisible=true;
	                this.hxData.brokerNames=res.brokerNames;
	                this.hxData.devName=res.devName;
	                this.hxhouse=res.houses;
	                this.hxData.brokerCustomerId=res.brokerCustomerId;
	                this.hxData.fee=res.fee;
	                this.hxData.customerName=res.customerName;
	                this.hxData.orderCode=res.orderCode;
	            });
			},
			lookProgress(orderCode){
				this.$router.push({
					path:"/refundapproval",
					query:{
						orderCode:orderCode
					}
				})
			},
			jumpDetail(type,orderCode){
				this.$router.push({
					path:"/orderpaiddetail",
					query:{
						type:type,
						orderCode:orderCode
					}
				})
			},
			tableSortChange(column) {
				if (column.order == "descending") {
					this.formData.sortFlag = "desc";
					this.loadData();
				} else {
					this.formData.sortFlag = "asc";
					this.loadData();
				}
			},
			resetForm(){
				for(let item in this.formData){
					this.formData[item]=""
				}
				this.formData.pageNum=1;
				this.formData.pageSize=10;
				this.formData.sortFlag="desc";
				this.loadData();
			},
			query(){
				this.formData.pageNum=1;
				this.loadData();
			},
			loadCity(){
	            this.$axios.post(`/city/cityList`).then((res) => {
	                this.citys=res.cityList;
	            });
	        },
	        loadisOrdev(){
	        	this.formData.devId="";
	            this.$axios.post(`/estate/devs/select/mapParam`,{cityId:this.formData.cityId}).then(res => {
	                this.devs=res;
	            });
	        },
			loadData(){
				this.$axios.post(`/cms/posCmsOrder/selectPosOrder`,this.formData).then(res => {
					this.tableData=res.list;
					this.total=res.total;
	            });
			},
			initTradeStatus(row, column, cellValue, index){
				if(cellValue==0){
					return "认筹-已下单"
				}else if(cellValue==1){
					return "认筹-待支付"
				}else if(cellValue==2){
					return "认筹-已付款"
				}else if(cellValue==6){
					if(row.orderStatus==3){
						return "认筹-已退款"
					}else if(row.orderStatus==4){
						return "认筹-退款中"
					}else if(row.orderStatus==5){
						return "认筹-退款拒绝"
					}else{
						return "类型获取异常！"
					}
				}
			},
			initRefundFlag(row, column, cellValue, index){
				if(row.tradeStatus==0 || row.tradeStatus==1 || row.tradeStatus==2 || (row.tradeStatus==6&&row.orderStatus==5)){
					return "否"
				}else{
					return "是"
				}
			},
			toFixedFn(row, column, cellValue, index) { //保留两位小数并且千分位展示
				if (cellValue != undefined && cellValue != null && cellValue.toString() != "") {
					let tempValue = parseFloat(cellValue)
					return tempValue.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
				}else{
					return "——"
				}
			},
			toFixedFn1(cellValue) { //保留两位小数并且千分位展示
				if (cellValue != undefined && cellValue != null && cellValue.toString() != "") {
					let tempValue = parseFloat(cellValue)
					return tempValue.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
				}
			},
			initAuditstatus(row, column, cellValue, index){
				switch (cellValue+"") {
                    case '1':
                        return "待审核"
                    case "2":
                        return "运营审核通过"
                    case "3":
                        return "财务审核通过"
                    case "4":
                        return "运营审核拒绝"
                    case "5":
                        return "财务审核拒绝"
                    case "6":
                        return "H3审核拒绝"
                    default:
                        return "——"
                }
			},
			initBpmsubStatus(row, column, cellValue, index){
				if (row.tradeStatus == 0 || row.tradeStatus == 1 || row.tradeStatus == 2) {
                    return "——";
                }
                if (cellValue == 1 || cellValue == '') {
                    return "不可提交"
                }
                if (cellValue == 2) {
                    return "提交成功"
                }
                if (cellValue == 3) {
                    return "驳回待提交"
                }
			},
			initBpmsAudStatus(row, column, cellValue, index){
				if (cellValue == 1) {
                    return "审核中"
                }else if (cellValue == 2) {
                    return "审核完成"
                }else if (cellValue == 3) {
                    return "审核拒绝"
                }else{
                	return "——"
                }
			},
			handleSizeChange(val){
				this.formData.pageSize = val;
		        this.loadData();
			},
			handleCurrentChange(val){
				this.formData.pageNum = val;
				this.loadData();
			},

		},
		mounted(){
			this.loadCity();
			this.loadData();
		}
	}
</script>

<style lang="stylus">
	
</style>






